package net.deuce.perf;

import org.springframework.beans.factory.InitializingBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.util.Properties;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;

public class ClientConfiguration implements InitializingBean {
    private File executable;
    private File testPlan;
    private Map<String, String> properties = new LinkedHashMap<String, String>();
    private List<String> remoteHosts;

    private Log log = LogFactory.getLog(getClass());

    public ClientConfiguration() {
        //log.trace("");
    }
    
    public ClientConfiguration(File testPlan) {
        //log.trace("");
        this.testPlan = testPlan;
    }

    public File getTestPlan() {
        //log.trace("");
        return testPlan;
    }

    public void setTestPlan(File testPlan) {
        //log.trace("");
        this.testPlan = testPlan;
    }

    public Map<String, String> getProperties() {
        //log.trace("");
        return properties;
    }

    public void setProperties(Map<String, String> properties) {
        //log.trace("");
        this.properties = properties;
    }

    public List<String> getRemoteHosts() {
        //log.trace("");
        return remoteHosts;
    }

    public void setRemoteHosts(List<String> remoteHosts) {
        //log.trace("");
        this.remoteHosts = remoteHosts;
    }

    public File getExecutable() {
        //log.trace("");
        return executable;
    }

    public void setExecutable(File executable) {
        //log.trace("");
        this.executable = executable;
    }

    public void afterPropertiesSet() throws Exception {
        //log.trace("");
        if (executable == null) {
            throw new RuntimeException("Missing executable property.");
        }
        if (testPlan == null) {
            throw new RuntimeException("Missing testPlan property.");
        }
        if (!executable.exists()) {
            throw new RuntimeException("No executable found at: " + executable.getAbsolutePath());
        }
        if (!testPlan.exists()) {
            throw new RuntimeException("No testPlan found at: " + testPlan.getAbsolutePath());
        }
    }
}
